import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { AuthModule } from './auth/auth.module';
import { TypeOrmModule } from '@nestjs/typeorm'
import { TestModule } from './test/test/test.module';
import { JwtModule } from '@nestjs/jwt';
import { CouponInfoModule } from './moudle/coupon/coupon_info/coupon_info.module';
import { CustomerCoupon } from './moudle/coupon/customer_coupon/entities/customer_coupon.entity';
import * as userDatabaseConfig from './config/userDatabaseConfig.json';
import * as couponDatabaseConfig from './config/couponDatabaseConfig.json';
import { SystemUserModule } from './moudle/system-user/system-user.module';
 import { CouponInfo } from './moudle/coupon/coupon_info/entities/coupon_info.entity';
import { CanaleRuleModule } from './moudle/rule/canale_rule/canale_rule.module';
import { CustomerInfoModule } from './moudle/daijia_customer/customer_info/customer_info.module';
import { DriverInfoModule } from './moudle/daijia_driver/driver_info/driver_info.module';
import { OrderInfoModule } from './moudle/daijia_order/order_info/order_info.module';
import { PaymentInfoModule } from './moudle/daijia_payment/payment_info/payment_info.module';
let envFilePath = '';
export const IS_DEV = process.env.RUNNING_ENV || '.env.dev';
if (IS_DEV === 'dev') {
  envFilePath = '.env.dev';
} else if (IS_DEV === 'test') {
  envFilePath = '.env.test';
} else {
  envFilePath = '.env.prod';
}

@Module({
  imports: [
    JwtModule.register({
      global: true, // 全局注册，避免重复导入
      secret: 'your-secret-key', // JWT 密钥
      signOptions: { expiresIn: '1h' }, // Token 过期时间
    }),
    ConfigModule.forRoot({
      isGlobal: true,
      envFilePath,
    }),
    TypeOrmModule.forRoot({
      "type": "mysql",
      "host": "127.0.0.1",
      "port": 3306,
      "username": "root",
      "password": "123456",
      "database": "daijia_system",
      "entities": [CouponInfo],
      "synchronize": true,
      "retryDelay": 500,
      "retryAttempts": 10,
      "autoLoadEntities": true
    }),
    AuthModule,
    TestModule,
    CouponInfoModule,
    CustomerCoupon,
    SystemUserModule,
    CanaleRuleModule,
    CustomerInfoModule,
    DriverInfoModule,
    OrderInfoModule,
    PaymentInfoModule
  ],
  controllers: [],
  providers: [],
})
export class AppModule {}
